package com;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;

import pages.AnyPage;
import pages.InternalPage;
import pages.LoginPage;
import pages.UserManagmentPage;

public class test extends TestBase{
	
	
	private UserManagmentPage userManagmentPage;
	private AnyPage anyPage;
	private LoginPage loginPage;
	private InternalPage internalPage;
	
	

	@Test
	public void createNweUserTest() throws Exception {
		
		goToPage("http://localhost/php4dvd/");
		loginTest("admin", "admin");
		goToUserManagmentPage();
		wait(900);
		List <Users> oldUserList = userManagmentPage.getUsers();
		
		System.out.print(oldUserList.toString());
		
	}
	
	
		
	private void choosUserRole(String userRole) {
		Select select = new Select(userManagmentPage.permissionField);
		select.selectByVisibleText(userRole);
	}



	private void feelTestUserCreatinForm(Users user) {

		userManagmentPage.userNameField.clear();
		userManagmentPage.userNameField.sendKeys(user.name);
		userManagmentPage.emailField.clear();
		userManagmentPage.emailField.sendKeys(user.email);
		userManagmentPage.passwordField.clear();
		userManagmentPage.passwordField.sendKeys(user.password);
		userManagmentPage.password2Field.clear();
		userManagmentPage.password2Field.sendKeys(user.password);		
	}
	
	private void clickSubmitButtonOnuserManagmentPage (){
		userManagmentPage.submitButton.click();
	}
	

	private void loginTest(String userName, String password) {
		loginPage.userNameFieldOnLoginPage.sendKeys(userName);
		loginPage.passwordField.clear();
		loginPage.passwordField.sendKeys(password);
		loginPage.loginButton.click();
	}

	private void goToPage(String url) {
		driver.get(url);
		loginPage = PageFactory.initElements(driver, LoginPage.class);
		internalPage = PageFactory.initElements(driver, InternalPage.class);
		anyPage = PageFactory.initElements(driver, AnyPage.class);
		userManagmentPage = PageFactory.initElements(driver, UserManagmentPage.class);
	}

	private void goToUserManagmentPage() {
		internalPage.userManagmentLink.click();
	}

}
